<link href="/assets/css/conmment.css" type="text/css" rel="stylesheet">
<div class="conmmentw">
  <div class="hot-messages">
    <div class="messages-box clearfix">
      <h3>热门评论</h3>
      <a class="m-btn">写评论<em><img src="/assets/img/messages.png"></em></a> </div>
    <div class="text-box">
      <textarea class="conmmenttextarea" onpropertychange='this.style.posHeight=this.scrollHeight' id='textarea' onfocus='textarea.style.posHeight=this.scrollHeight' placeholder="请输入您的留言"></textarea>
      <div class="title-box clearfix">
        <div class="title-img"><img src="/assets/img/title.png"></div>
        <input type="button" id="messagesubmit" value="提交" class="in-btn" style="cursor:pointer;">
      </div>
    </div>
    <div class="user-messages" id="usermessages">正在加载...</div>
  </div>
</div>
<script type="text/javascript">
$(function(){
  $("a.m-btn").click(function(event) {
      $(".text-box").fadeIn();
  });
  //提交评论
  var id = '{$Think.get.id}';
  $("#messagesubmit").click(function(event) {
    var ucontent = $("#textarea").val();
    if($.trim(ucontent)==''){
       alert('请输入评论内容');
       return false;
    }
    var savetel_url = "/Home/Article/savemessage";
    var teldata = {"ucontent":ucontent,"id":id,"type":type,random:Math.random()};
    $.ajax({
      url:savetel_url,
      data:teldata,
      type:"POST",
      dataType:"JSON",
      success:function (data){
          if(data.ret==1){
              $("#textarea").val(null);
              alert('评论成功');
              getmesage(id);
          }else if(data.ret==0){
              alert('评论失败');
          }else if(data.ret==-2){
              alert('请先登陆');
              location.href="{:C('LOGINADDRES')}{$geturl}";
          }else{
              alert('获取数据失败');
          }
      }
    });

  });

    function getmesage(id){
        var savetel_url = "/Home/Article/getmessages";
        var teldata = {"id":id,"type":type,random:Math.random()};
        $.ajax({
            url:savetel_url,
            data:teldata,
            type:"POST",
            dataType:"HTML",
            success:function (data){
                $("#usermessages").html(data);
            }
        });
    }
    getmesage(id);

});
</script>
